package wiki.generic.concretemed;

import wiki.generic.bar.BarLink;
import wiki.generic.bar.BarLinkFactory;
import wiki.generic.bar.SideBar;
import wiki.generic.io.MapDataReader;
import wiki.generic.io.SideBarLinksReader;
import wiki.generic.io.SideBarWriter;
import wiki.generic.managers.BarManager;
import wiki.generic.med.BarService;
/**
 * 
 * @author <p><strong>JwTeam</strong></p> 
 *
 */
public class BarServiceMediator implements BarService{

	private BarLinkFactory bfactory;
	private SideBarWriter lwriter;
	private MapDataReader coursesReader;
	private SideBarLinksReader lreader;
	
	public BarServiceMediator(BarLinkFactory bfactory,SideBarWriter lwriter,
			MapDataReader coursesReader) {
		super();
		this.bfactory=bfactory;
		this.lwriter = lwriter;
		this.coursesReader = coursesReader;
	}

	public SideBar getSideBar(String corso) {
		return BarManager.getSingleton().getBmap().get(corso);
	}
	
	public void addNewLink(String corso,String category, String name, String URL){
		BarManager.getSingleton().getBmap().get(corso).addLink(category, bfactory.generateBarLink(name, URL));
		lwriter.printSideBar(BarManager.getSingleton().getBmap().get(corso), coursesReader.getMap().get(corso)+"/"+lreader.getFile());
	}
	
	public void deleteSideBarCategory(String corso,String category){
		SideBar bar=BarManager.getSingleton().getBmap().get(corso);
		bar.deleteCategory(category);
		lwriter.printSideBar(bar, coursesReader.getMap().get(corso)+"/"+lreader.getFile());
	}
	
	public void deleteLink(String corso,String category, String name){
		SideBar bar=BarManager.getSingleton().getBmap().get(corso);
		bar.deleteLink(category, name);
		lwriter.printSideBar(bar, coursesReader.getMap().get(corso)+"/"+lreader.getFile());
	}
	
	public void setNewLinkName(String corso,String category,String name, String newName){
		SideBar bar=BarManager.getSingleton().getBmap().get(corso);
		bar.renameLink(category, name, newName);
		lwriter.printSideBar(bar, coursesReader.getMap().get(corso)+"/"+lreader.getFile());
	}

	@Override
	public BarLink generateLink(String name, String URL) {
		return bfactory.generateBarLink(name, URL);
	}

	@Override
	public void setBreader(SideBarLinksReader lreader) {
		this.lreader=lreader;
		BarManager.getSingleton().setBmap(lreader.getSideBar(coursesReader.getMap()));
	}

	
	
	
	
}
